package com.msc.mobilecomputing.adapters;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.msc.mobilecomputing.R;
import com.msc.mobilecomputing.model.TravelLocation;
import com.msc.mobilecomputing.utils.FontUtils;

public class TravelLocationAdapter extends ArrayAdapter<TravelLocation> {

	private Context context;
	private LayoutInflater inflater;
	private int resource;
	private List<TravelLocation> items;

	public TravelLocationAdapter(Context context, int resource,
			List<TravelLocation> items) {
		super(context, resource, 0, items);

		this.context = context;
		this.inflater = LayoutInflater.from(context);
		this.resource = resource;
		this.items = items;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		View view = null;
		if (convertView == null) {
			view = inflater.inflate(resource, null);
			FontUtils.setCustomFont(view, context.getAssets());
		} else {
			view = convertView;
		}

		TextView textTitle = (TextView) view
				.findViewById(R.id.main_list_row_title);
		TextView textSubtitle = (TextView) view
				.findViewById(R.id.main_list_row_subtitle);

		ImageView image = (ImageView) view
				.findViewById(R.id.main_list_row_image);

		TravelLocation item = items.get(position);

		textTitle.setText(item.getName());
		textSubtitle.setText(item.getSummary());
		image.setImageResource(item.getImageResource());

		return view;
	}
}
